from django.db import models


class Member(models.Model):
    sex_choices = (
        (0, '男'),
        (1, '女'),
    )
    name = models.CharField('姓名', max_length=30)
    age = models.CharField('年龄', max_length=30)
    sex = models.SmallIntegerField('性别', choices=sex_choices, default=0)
    occupation = models.CharField('职业', max_length=30)
    phone_num = models.CharField('手机号', max_length=14, null=True)
    email = models.EmailField('邮箱', blank=True)
    city = models.CharField('城市', max_length=30)
    register_date = models.DateTimeField('注册时间', auto_now=True)

    def __str__(self):
        return "<%s, %s>" % (self.name, self.phone_num)

    class Meta:
        # 通过db_table自定义数据表名
        db_table = 'member'


def get_all():
    Member.objects.all().count()
    Member.objects.reverse().first()
    Member.objects.all().filter(city__in='wuhan')
    Member.objects.all().filter(city__in='wuhan').filter(email__in='ww')
    Member.objects.all().filter(city__in='wuhan').filter(email__isnull='ww')
